package com.kingsailor.gunsmith;

import edu.jetwinner.i18n.EasyMultipleMessageSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.theme.CookieThemeResolver;

/**
 * @author xulixin
 */
@Configuration
public class GunsmithAppConfig implements WebMvcConfigurer {

    @Value("${gunsmith.skin.name:softed}")
    private String skinName;

    @Bean
    public MessageSource messageSource() {
        EasyMultipleMessageSource messageSource = new EasyMultipleMessageSource();
        messageSource.setBasename("classpath*:i18n/messages");
        messageSource.setCacheSeconds(-1);
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

    @Bean
    public ThemeResolver themeResolver() {
        CookieThemeResolver themeResolver = new CookieThemeResolver();
        themeResolver.setDefaultThemeName(skinName);
        return themeResolver;
    }

}
